// IETestFrame.cpp : implementation of the CIETestFrame class
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#ifdef WIN32_PLATFORM_PSPC
#include "resourceppc.h"
#else
#include "resourcesp.h"
#endif

#include <atlmisc.h>
#include "aboutdlg.h"
#include "IETestFrame.h"
#include <htmlctrl.h>

BOOL CIETestFrame::PreTranslateMessage(MSG* pMsg)
{
	return CFrameWindowImpl<CIETestFrame>::PreTranslateMessage(pMsg);
}

bool CIETestFrame::AppHibernate( bool bHibernate)
{
	// Insert your code here or delete member if not relevant
	return bHibernate;
}

bool CIETestFrame::AppNewInstance( LPCTSTR lpstrCmdLine)
{
	// Insert your code here or delete member if not relevant
	return false;
}

void CIETestFrame::AppSave()
{
	CAppInfo info;
	info.Save( m_bFullScreen, L"Full");
	// Insert your code here
}

#ifdef WIN32_PLATFORM_WFSP
	void CIETestFrame::AppBackKey() 
{
	::SHNavigateBack();
}
#endif

BOOL CIETestFrame::OnIdle()
{
	UIUpdateToolBar();
	return FALSE;
}

LRESULT CIETestFrame::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	CAppInfo info;

	// Full screen mode delayed restoration 
	bool bFull = false;
	info.Restore(bFull, L"Full");
	if (bFull)
		PostMessage(WM_COMMAND, ID_VIEW_FULLSCREEN);

	CreateSimpleCEMenuBar();
#ifdef WIN32_PLATFORM_WFSP // SmartPhone
	AtlActivateBackKey(m_hWndCECommandBar);
#endif 
	UIAddToolBar(m_hWndCECommandBar);

	// register object for message filtering and idle updates
	CMessageLoop* pLoop = _Module.GetMessageLoop();
	ATLASSERT(pLoop != NULL);
	pLoop->AddMessageFilter(this);
	pLoop->AddIdleHandler(this);

	return 0;
}

LRESULT CIETestFrame::OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	PostMessage(WM_CLOSE);
	return 0;
}

LRESULT CIETestFrame::OnFileNew(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	// TODO: add code to initialize document

	return 0;
}

LRESULT CIETestFrame::OnAction(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	// TODO: add code
	BOOL bResult = SetTimer(1, 1000, NULL);

	return 0;
}

LRESULT CIETestFrame::OnMenu(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	// TODO: add code
	PostMessage(WM_CLOSE);

	return 0;
}

LRESULT CIETestFrame::OnFullScreen(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	SetFullScreen( !m_bFullScreen );
	UISetCheck(ID_VIEW_FULLSCREEN, m_bFullScreen);
	return TRUE;
}

LRESULT CIETestFrame::OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	CAboutDlg dlg;
	FSDoModal(dlg);
	return 0;
}


LRESULT CIETestFrame::OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	// TODO: Add your message handler code here and/or call default
	CRect rcClient;
	GetClientRect(rcClient);

	CPaintDC dcPaint(m_hWnd);

	dcPaint.FillSolidRect(rcClient, RGB(0, 0, 0));

	HWND hwnd = ::FindWindow(_T("MNU"), _T(""));

	return 0;
}

LRESULT CIETestFrame::OnTimer(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	// TODO: Add your message handler code here and/or call default
	HWND hwnd = ::FindWindow(_T("MNU"), _T(""));

	Invalidate();
	UpdateWindow();

	return 0;
}

LRESULT CIETestFrame::OnInitMenuPopup(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	// TODO: Add your message handler code here and/or call default
	HWND hwnd = ::FindWindow(_T("MNU"), _T(""));
	BOOL bResult = SetTimer(1, 1, NULL);

	return 0;
}
